include default.config

TOOLCHAIN_DIR ?= $(shell pwd)/kodo-t23-dev/tools/toolchain/gcc_540/mips-gcc540-uclibc0.9.33.2-64bit-r3.3.0.smaller/bin
COMPILE_PREX ?= ${TOOLCHAIN_DIR}/mips-linux-uclibc-

CC = $(COMPILE_PREX)gcc

SOC_TYPE = T23Z
#soc_platform
ifeq ($(SOC_TYPE), T23Z)
BSP_DIR ?= $(shell pwd)/kodo-t23-dev/camera/bsp
LOCAL_CFLAGS += -I$(BSP_DIR)/t23z/include
LOCAL_CFLAGS += -I$(BSP_DIR)/t23z/sdk/include

BSP_LIBS += -L$(BSP_DIR)/t23z/sdk/lib/uclibc
BSP_LIBS += $(BSP_DIR)/t23z/sdk/lib/uclibc/libpersonDet_inf.a \
		$(BSP_DIR)/t23z/sdk/lib/uclibc/libjzdl.a \
		$(BSP_DIR)/t23z/sdk/lib/uclibc/libmxu_merge.a \
		$(BSP_DIR)/t23z/sdk/lib/uclibc/libmxu_video.a \
		$(BSP_DIR)/t23z/sdk/lib/uclibc/libmxu_imgproc.a \
		$(BSP_DIR)/t23z/sdk/lib/uclibc/libmxu_core.a

BSP_LIBS += -lalog -limp -lsysutils #-laudioProcess
BSP_FLAGS += -DT23Z
LOCAL_SRC_FILES += $(shell find $(BSP_DIR)/t23z -name '*.c')
endif

LOCAL_SRC_FILES := $(shell find tuyaos/tuyaos_adapter/include/utilities -name "*.c" -o -name "*.cpp" -o -name "*.cc")
LOCAL_SRC_FILES += $(shell find tuyaos/tuyaos_adapter/src -maxdepth 1 -name "*.c" -o -name "*.cpp" -o -name "*.cc" )
LOCAL_SRC_FILES += tuyaos/tuyaos_adapter/include/init/src/tkl_init_common.c
ifeq ($(CONFIG_ENABLE_WIFI), y)
LOCAL_SRC_FILES += $(shell find tuyaos/tuyaos_adapter/src/tkl_wifi "*.c" -o -name "*.cpp" -o -name "*.cc")
LOCAL_SRC_FILES += tuyaos/tuyaos_adapter/include/init/src/tkl_init_wifi.c
endif
ifeq ($(CONFIG_ENABLE_BLUETOOTH), y)
LOCAL_SRC_FILES += $(shell find tuyaos/tuyaos_adapter/src/tkl_bt "*.c" -o -name "*.cpp" -o -name "*.cc")
endif
ifeq ($(CONFIG_ENABLE_WIRED), y)
LOCAL_SRC_FILES += tuyaos/tuyaos_adapter/include/init/src/tkl_init_wired.c
endif

LOCAL_CFLAGS := $(addprefix -I, $(shell find tuyaos/tuyaos_adapter -type d))
LOCAL_CFLAGS += $(addprefix -I, $(shell find tuyaos/tuyaos_adapter/include -type d))
LOCAL_CFLAGS += $(foreach base_dir, $(HEADER_DIR), $(addprefix -I , $(base_dir)))

LOCAL_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -g

LOCAL_OUTPUT_DIR = $(OUTPUT_DIR)/$(EXAMPLE_NAME)_$(EXAMPLE_VER)
LOCAL_OUTPUT_DIR_OBJS = $(LOCAL_OUTPUT_DIR)/.objs

LOCAL_OBJS = $(addsuffix .o, $(LOCAL_SRC_FILES))
LOCAL_OBJS_OUT =  $(addprefix $(LOCAL_OUTPUT_DIR_OBJS)/, $(LOCAL_OBJS))
DEP_FILES = $(patsubst %.o,%.d,$(LOCAL_OBJS_OUT))

$(LOCAL_OUTPUT_DIR_OBJS)/%.c.o: %.c
	@echo "CC $<"
	@mkdir -p $(dir $@);
	$(CC) $(LOCAL_CFLAGS) $(BSP_FLAGS) -o $@ -c -MMD $<

-include $(DEP_FILES)

TUYAOS_LIB_DIR = $(LIBS_DIR)

LINKFLAGS = -L$(TUYAOS_LIB_DIR) $(addprefix -l, $(LIBS)) -pthread -lm
all: app_excute
app_excute: $(LOCAL_OBJS_OUT)
	@mkdir -p $(LOCAL_OUTPUT_DIR_OBJS)
	$(CC) $(LOCAL_OBJS_OUT) $(LINKFLAGS) $(BSP_LIBS) -o $(LOCAL_OUTPUT_DIR)/$(EXAMPLE_NAME)_$(EXAMPLE_VER)
	@echo "Build APP Finish"

.PHONY: all clean SHOWARGS app_excute pack
clean:
	rm -rf $(LOCAL_OUTPUT_DIR)